﻿using Xejen.Ipc.Framework.Flows;
using Xejen.Ipc.Framework.Steps;
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

namespace Xejen.Ipc.Framework.Controllers
{
    /// <summary>
    /// 表示流程控制器，决定着流程应该如何执行
    /// </summary>
    /// <typeparam name="TData"><inheritdoc cref="IFlow{TData}" path="/typeparam[@name='TData']"/></typeparam>
    /// <creator>marc</creator>
    public interface IController<TData>
        where TData : new()
    {
        /// <summary>
        /// 控制器名称
        /// </summary>
        string Name { get; }
        /// <summary>
        /// 步骤列表
        /// </summary>
        IReadOnlyList<IStep<TData>> Steps { get; }

        /// <summary>
        /// 流程控制器进入时的事件
        /// </summary>
        event EventHandler<ControllerEventArgs<TData>> Started;
        /// <summary>
        /// 流程控制器出去时的事件
        /// </summary>
        event EventHandler<ControllerEventArgs<TData>> Completed;
        /// <summary>
        /// 流程控制器发生错误时的事件
        /// </summary>
        event EventHandler<ErrorEventArgs<TData>> Error;

        /// <summary>
        /// 运行本流程
        /// </summary>
        /// <param name="context"><inheritdoc cref="IFlowExecutionContext{TData}" path="/summary"/></param>
        /// <param name="cancellationToken">取消动作的令牌</param>
        Task RunAsync(IFlowExecutionContext<TData> context, CancellationToken cancellationToken = default);
    }
}
